﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using FarseerPhysics.Dynamics;
using FarseerPhysics.Dynamics.Contacts;
using Animation;
using MapLibrary.Players;
using MapLibrary.Players.CollisionResponse;

namespace Enemies
{
    using CollisionCategory = CollisionResponseManager.CollisionCategory;
    using MapLibrary.Particles.Emitters;
    using MapLibrary;
    using MapLibrary.Particles;

    class Tuberculosis : Enemy
    {

        private TriggeredParticleEmitter deathEmitter;

        public Tuberculosis()
        {
            this.CollisionCategory = CollisionCategory.Tuberculosis;

            MAX_VELOCITY_X = 0.1f;

            OnInitialization += LoadDeathEmitter;
            maxHealth = 100;
            health = maxHealth;

            Hookable = false;
        }

        protected void LoadDeathEmitter()
        {
            deathEmitter = new TriggeredEmitterFromData(World.ParticleManager, this, @"DeathParticleEffect/TuberculosisDeath");
        }

        public override bool MyOnCollision(Fixture f1, Fixture f2, Contact contact)
        {
            Sprite s1 = f1.Body.UserData as Sprite;
            Sprite s2 = f2.Body.UserData as Sprite;

            if (s1 == null || s2 == null)
            {
                return true;
            }

            LevelCollisionRegion r = f2.Body.UserData as LevelCollisionRegion;
            if (r != null)
            {
                if (r.Type == "Mucus")
                    return false;
            }

            Particle p1 = f2.Body.UserData as Particle;
            if (p1 != null)
                return false;

            Player p = s2 as Player;
            if (p != null)
            {
                if (p.IsShieldActive())
                {
                    World.CurrentLevel.AddBodyToRemove(this);
                    Die();
                }
            }

            Tuberculosis t = s2 as Tuberculosis;
            if (t != null)
                return false;

            return true;
        }

        protected override void Die()
        {
            base.Die();

            deathEmitter.Trigger();
        }
    }
}
